<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="css/login.css" rel="stylesheet" />
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="js/login.js"></script>
    <title>昵称设置</title>
    <script src="js/layer/layer.js"></script>
</head>

<body>
    <div id="login">
        <div id="header">
            <img class="back" src="images/back.png" alt="">
        </div>
        <div id="content">
            <div id="fp">
                <strong>昵称设置</strong>
            </div>
            <form action="" id="form">
                <input type="text" placeholder="请输入昵称" id="nickname">
                <div class="user">
                    <input type="checkbox" name="checkbox" value="" id="checkbox">
                    <span>我同意
                        <a href="register_protocol.html">《用户协议及隐私设置》</a>
                    </span>
                </div>

            </form>
            <div id="button">
                <button class="login">完成</button>
            </div>
        </div>
        <div id="bottom">
            <strong>已有云网账号？
                <a href="login.html" id="zhuce">登录</a>
            </strong>
        </div>

    </div>
    <div class="pop">
        <img src="images/xiazai.jpg" alt="">
        <p>扫描二维码下载APP</p>
        <div class="close1"></div>
    </div>
    <div class="mask">

    </div>
    <script>
        $(function () {
            $(".back").click(function () {
                $(window).attr('location', "register_setPassword.html");
            });
            $(".close1").click(function () {
                $('.pop').hide();
                $('.mask').hide();
            });
            $('.pop').hide();
            $('.mask').hide();

            $(".login").click(function () {

                if (localStorage.flag == "true") {
                    localStorage.nickname = $("#nickname").val();
                    console.log(localStorage.mobile);
                    console.log(localStorage.password);
                    console.log(localStorage.nickname);

                    if ($("[name = 'checkbox']:checkbox:checked").length == 1) {

                        if (localStorage.nickname === '') {
                            // alert("请填写昵称")
                            layer.msg("请填写昵称");
                        } else {
                            $.ajax({
                                type: 'POST',
                                url: `${localStorage.top}api/user/register`,
                                data: {

                                    mobile: localStorage.mobile,
                                    password: localStorage.password,
                                    nickname: localStorage.nickname,
                                    username: localStorage.mobile,
                                    code: localStorage.invite_code
                                },

                                success: function (data) {
                                    console.log(data);
                                    // alert("注册成功");
                                    layer.msg("注册成功！");
                                    localStorage.flag = "false";

                                    if (localStorage.invite_code !== undefined) {

                                        $('.pop').show();
                                        $('.mask').show();

                                    } else {
                                        $(window).attr('location', "login.html");
                                    }

                                }
                            });
                        }

                    } else {
                        layer.msg("请选择用户协议及隐私设置");
                    }
                    

                }else{
                    layer.msg("请验证手机号")
                }


                // console.log($("#nickname").val());
            });
        })
    </script>
</body>

</html>